# coding=utf-8
from google.appengine.ext import db
from pages.postpage import Topics
import time
import webapp2

class ListTopicPage(webapp2.RequestHandler):
    
    def oldwayOfDisplaying(self):
#        topics = db.GqlQuery("SELECT * FROM Topics ORDER BY t_date DESC")
        topics = Topics.gql("ORDER BY t_date ASC")
#        while topics.count():
#            db.delete(topics.fetch(200))
#            time.sleep(0.5)
        self.response.write('========== begin ======= <br>')
        for topic in topics:
#            self.response.write(topic.t_id)
            self.response.write('key\'s id -> %d, topic -> %s <br>' % (topic.key().id(),topic.t_topic))
            self.response.write('url -> <a href="%s">google</a> <br>' % (topic.t_url))
            self.response.write('content -> %s <br><br><br>' % (topic.t_content))
        self.response.write('========== end =======')
        
    def newWay(self):
        topics = Topics.all()
        topics.order("-t_date")
        results = topics.fetch(100)
        for each in results:
            self.response.write('t_id-> %d, t_topic -> %s<br>' % (each.t_id,each.t_topic))
            self.response.write('url -> <a href="%s">google</a> <br>' % (each.t_url))     
    
    def get(self):
        self.oldwayOfDisplaying()

